<template>
  <el-dialog
    :visible="visible"
    center
    :show-close="false"
    width="640px"
  >
    <div class="b g3 f16 tl" slot="title">
      <div class="ks-row-between pl15 pr15">
        <span>{{$t('sys.new')}}</span>
        <span
          class="el-icon-close g9 f26 poi"
          @click="handleCancel"
        ></span>
      </div>
    </div>

    <el-form ref="form" :model="form" label-width="80px" class="pl30 pr30">
      <el-form-item
        :label="$t('sys.type')"
        porp="type"
        :rules="[{
          required: true,message: $t('sys.type_not_null') }
        ]" >
        <el-input prop="form.name" :maxlength="128" show-word-limit/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="tr">
      <el-button @click="handleCancel">{{$t('sys.cancel')}}</el-button>
      <el-button type="primary" @click="handleSubmit">{{$t('sys.confirm')}}</el-button>
    </div>
  </el-dialog>
</template>

<script>

export default {
  name: 'TypeForm',
  data() {
    return {
      id: 0,
      visible: false,
      confirmLoading: false,
      form: {}
    }
  },
  created() {

  },
  methods: {

    add() {
      this.visible = true
      this.$nextTick(() => {
        const model = { name: '' }
        this.form = model
      })
    },

    async handleSubmit() {

      try {
        await this.$refs.form.validate()
        const model = {
          name: name.trim()
        }
        // 新增
        this.confirmLoading = true
        createEscalateType(model)
          .then(res => {
            this.visible = false
            this.$message.success(res.message, 1)
            this.resetForm()
            this.$emit('ok', Object.assign({}, model))
          })
          .finally(() => {
            this.confirmLoading = false
          })
      } catch (error) {
        console.log(error)
      }
    },

    handleCancel() {
      this.visible = false
      this.resetForm()
    },

    resetForm() {
      this.id = 0
      this.$nextTick(() => {
        this.$refs.form.resetFields()
        this.$refs.form.clearValidate()
      })
    }
  }
}
</script>

<style></style>
